// pages/login/login.js
import {
	HttpApi
} from '../../../model/index.js'
const httpApi = new HttpApi

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		communityId:"",
		roomNumber:"",
    yuyue:""
	},
	onLoad: function (options) {
    var login = wx.getStorageSync('login')
   
		console.log(options.communityId)
    
    if (options.yuyue != 1){
      options.yuyue = 0
    }
    console.log(options.yuyue)
    this.setData({ communityId: options.communityId, yuyue: options.yuyue })
	},
	roomNumInput:function(e)
	{
		console.log("roomNumInput:", e.detail.value)
		this.setData({
			roomNumber: e.detail.value
		})
	},
	submit() {
    var _this = this;
    var communityId = this.data.communityId;
    var roomNumber = this.data.roomNumber;
    if (this.data.yuyue ==1){
      wx.showLoading({
        title: '提交中',
      })
      console.log("communityId:" + this.data.communityId + "roomNumber:" + this.data.roomNumber)
      //调用edituser
      httpApi.editUser(this.data.communityId, this.data.roomNumber).then(res => {
        if (res.code == 0) {
          wx.hideLoading()
          wx.reLaunch({
            url: "../book/book"
          })
        }
      })
    }else{
      wx.showLoading({
        title: '提交中',
      })
      console.log("communityId:" + this.data.communityId + "roomNumber:" + this.data.roomNumber)
      //调用edituser
      httpApi.editUser(this.data.communityId, this.data.roomNumber).then(res => {
        if (res.code == 0) {
          wx.hideLoading()
          wx.reLaunch({
            url: "../u_main/u_main"
          })
        }
      })
    }
	}
})
